package com.llmops.core.node;

import com.llmops.core.Node;
import com.llmops.core.Context;
import com.llmops.core.NodeProperty;
import lombok.Data;
import org.apache.logging.log4j.util.Strings;

import java.util.Map;

public class StartNode extends Node {
    private UserInputNodeProperty property = new UserInputNodeProperty();
    @Data
    public static class UserInputNodeProperty extends NodeProperty {
        private String input;
    }
    public StartNode(String id, String title, Map<String, Object> config) {
        super(id,title,config);
        if(config!=null && config.containsKey("input")){
            this.property.setInput((String)config.get("input"));
        }
    }

    @Override
    public void execute(Context context) {
        String out;
        if(Strings.isNotBlank(property.getInput())){
            out = context.fillVariable(context, property.getInput());
        }else{
            out = context.getVariable("input");
        }
        context.setVariable(getId() + "_output", out);
        logger.info(getId() + "_output={}", out);
    }

    @Override
    public String getType() {
        return "start";
    }
}